package com.chanyachting.emall.domain;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.chanyachting.emall.dao.YellowpagesubcategoryDAO;
import com.chanyachting.emall.domain.base.BaseYellowpagesubcategory;

/**
 * This is the object class that relates to the yellowpagesubcategory table.
 * Any customizations belong here.
 */
public class Yellowpagesubcategory extends BaseYellowpagesubcategory {

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Yellowpagesubcategory () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Yellowpagesubcategory (java.lang.Integer _id) {
		super(_id);
		
		Yellowpagesubcategory subcategory=(Yellowpagesubcategory)new YellowpagesubcategoryDAO().load(Yellowpagesubcategory.class, _id);
		
		if(subcategory!=null){
			
			try {
				BeanUtils.copyProperties(this, subcategory);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * Constructor for required fields
	 */
	public Yellowpagesubcategory (
		java.lang.Integer _id,
		java.lang.Integer _categoryId) {

		super (
			_id,
			_categoryId);
	}
/*[CONSTRUCTOR MARKER END]*/
	
	public static List list(){
		
		
		return new YellowpagesubcategoryDAO().find("from Yellowpagesubcategory");
	}
	
	
	public static List listByCategoryId(int categoryId){
		
		String args[]={String.valueOf(categoryId)};
		
		return new YellowpagesubcategoryDAO().find("from Yellowpagesubcategory where categoryId=?",args);
	}
	
	
	public List getKeywordList(){

		return Yellowpagekeyword.listBySubCategory(this.getId());
	}
	
	
	public boolean save(){
		
		new YellowpagesubcategoryDAO().save(this);
		
		return true;
	}
	
	public boolean update(){
		
		new YellowpagesubcategoryDAO().update(this);
		
		return true;
	}
	
	
	public boolean delete(){
		
		List list=this.getKeywordList();
		
		if(list==null || list.size()<1){
			
			new YellowpagesubcategoryDAO().delete(this);
			
		}else{
			
			return false;
		}

		return true;
	}
	
	
	
	
	
}